//
//  UIBarButtonItem+Extension.m
//  JL网易彩票progress
//
//  Created by sunjinliang on 15/11/7.
//  Copyright © 2015年 sunjinliang. All rights reserved.
//

#import "UIBarButtonItem+Extension.h"

@implementation UIBarButtonItem (Extension)
+(UIBarButtonItem *)itemWithTitle:(NSString *)title norImage:(NSString *)norimage helImage:(NSString*)helImage targert:(id)targert action:(SEL)action{
    //1创建按钮
    UIButton * btn=[UIButton buttonWithType:UIButtonTypeCustom];
    //2设置图片
     if (norimage!=nil&&![norimage isEqualToString:@""]) {
          [btn setImage:[UIImage imageNamed:norimage] forState:UIControlStateNormal];
          
     }
     if (helImage!=nil&&![helImage isEqualToString:@""]) {
          [btn setImage:[UIImage imageNamed:helImage] forState:UIControlStateHighlighted];
     }
    //3设置标题
     if (title!=nil&&![title isEqualToString:@""]) {
          [btn setTitle:title forState:UIControlStateNormal];
     }
    //4设置frame
    
    [btn sizeToFit];
    //5添加监听事件
    [btn addTarget:targert action:action forControlEvents:UIControlEventTouchUpInside];
    //6返回item
    
    return [[UIBarButtonItem alloc]initWithCustomView:btn];
    
    
    
}

@end
